package LeetCode;

/**
 * @Author Kechelle
 * @Date 2020/9/27 16:31
 * @Version 1.0
 */
public class Code35 {
    public static int searchInsert(int[] nums, int target) {
        int left = 0;
        int right = nums.length;
        while (left<right){
            int mid = (left+right)/2;
            if (nums[mid] >= target){
                right = mid;
            }else {
                left = mid+1;
            }
        }
        return left;
    }

    public static int searchInsert1(int[] nums, int target) {
        for (int i=0;i< nums.length;i++){
            if (nums[i]>=target){
                return i;
            }
        }
        return nums.length;
    }

    public static void main(String[] args) {
        int[] nums = {1,3,5,6};
        System.out.println(searchInsert1(nums,2));
    }
}
